package search;

/**
 * @author yzh
 * @data 2021/3/30 20:52
 * 不需要排序，从头到尾搜索即可
 * 时间复杂度：O(n)
 */
public class 顺序 {
    public static void main(String[] args) {
        int[] nums = {3, 5, 1, 21, 45};
        int len = nums.length, target = 1, index = -1;
        for (int i = 0; i < len; i++) {
            if (nums[i] == target) index = i;
        }
        if (index == -1) System.out.println("target is not in nums");
        else System.out.println("target is in nums, in " + (index + 1));
    }
}
